1
|
|
|
/** global: UB */ |
2
|
|
|
|
3
|
|
|
/*! STRING ARRAY UTILS */ |
4
|
|
|
|
5
|
|
|
var arrayFuncs = { |
6
|
|
|
|
7
|
|
View Code Duplication |
indexOfCI: function(value){ |
|
|
|
|
8
|
|
|
var list = this; |
9
|
|
|
if (list.length == 0) { |
|
|
|
|
10
|
|
|
return -1; |
11
|
|
|
} |
12
|
|
|
var list = this; |
|
|
|
|
13
|
|
|
for (var i = 0, il = list.length;i<il;i++){ |
14
|
|
|
var str = list[i]; |
15
|
|
|
if (str && str.constructor === String) { |
16
|
|
|
if (str.equalsCI(value)){ |
17
|
|
|
return i; |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
return -1; |
22
|
|
|
}, |
23
|
|
|
|
24
|
|
View Code Duplication |
lastIndexOfCI: function(value){ |
|
|
|
|
25
|
|
|
var list = this; |
26
|
|
|
if (list.length == 0) { |
|
|
|
|
27
|
|
|
return -1; |
28
|
|
|
} |
29
|
|
|
for (var i = list.length-1;i>=0;i--){ |
30
|
|
|
var str = list[i]; |
31
|
|
|
if (str && str.constructor === String) { |
32
|
|
|
if (str.equalsCI(value)){ |
33
|
|
|
return i; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
return -1; |
38
|
|
|
}, |
39
|
|
|
|
40
|
|
|
removeCI: function(value, stringReplace = false){ |
41
|
|
|
var list = this; |
42
|
|
|
for (var i = 0, il = list.length;i<il;i++){ |
43
|
|
|
var str = list[i]; |
44
|
|
|
if (str && str.constructor === String) { |
45
|
|
|
if (stringReplace){ |
46
|
|
|
|
47
|
|
|
// remove substring within string items |
48
|
|
|
list[i] = str.removeAll(find, false, false); |
|
|
|
|
49
|
|
|
|
50
|
|
|
}else{ |
51
|
|
|
|
52
|
|
|
// remove entire items |
53
|
|
|
if (str.equalsCI(value)) { |
54
|
|
|
list.splice(i, 1); |
55
|
|
|
i--; |
|
|
|
|
56
|
|
|
il--; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
}, |
62
|
|
|
|
63
|
|
|
removeIfContains: function(value, caseSensitive = true){ |
64
|
|
|
var list = this; |
65
|
|
|
for (var i = 0, il = list.length;i<il;i++){ |
66
|
|
|
|
67
|
|
|
// remove entire items if string item contains the given substring |
68
|
|
|
var str = list[i]; |
69
|
|
|
if (str && str.constructor === String && str.smartContains(value, caseSensitive)) { |
70
|
|
|
list.splice(i, 1); |
71
|
|
|
i--; |
|
|
|
|
72
|
|
|
il--; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
}, |
76
|
|
|
removeIfBeginsWith: function(value, caseSensitive = true, trimAndCheck = false){ |
77
|
|
|
return this.removeIfStartsWith(value, caseSensitive, trimAndCheck); |
78
|
|
|
}, |
79
|
|
|
removeIfStartsWith: function(value, caseSensitive = true, trimAndCheck = false){ |
80
|
|
|
var list = this; |
81
|
|
|
for (var i = 0, il = list.length;i<il;i++){ |
82
|
|
|
|
83
|
|
|
// remove entire items if string item starts with the given substring |
84
|
|
|
var str = list[i]; |
85
|
|
|
if (str && str.constructor === String && str.smartStartsWith(value, null, caseSensitive, trimAndCheck)) { |
86
|
|
|
list.splice(i, 1); |
87
|
|
|
i--; |
|
|
|
|
88
|
|
|
il--; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
}, |
92
|
|
|
removeIfEndsWith: function(value, caseSensitive = true, trimAndCheck = false){ |
93
|
|
|
var list = this; |
94
|
|
|
for (var i = 0, il = list.length;i<il;i++){ |
95
|
|
|
|
96
|
|
|
// remove entire items if string item ends with the given substring |
97
|
|
|
var str = list[i]; |
98
|
|
|
if (str && str.constructor === String && str.smartEndsWith(value, null, caseSensitive, trimAndCheck)) { |
99
|
|
|
list.splice(i, 1); |
100
|
|
|
i--; |
|
|
|
|
101
|
|
|
il--; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
}, |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
none:null |
108
|
|
|
}; |
109
|
|
|
|
110
|
|
|
// register funcs |
111
|
|
|
UB.registerFuncs(Array.prototype, arrayFuncs); |
112
|
|
|
|